<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			var flag=false
			function fun(){
				let img=document.querySelector(".con>img")//父子选择器
				let h1=document.querySelector(".con>h1")
				if(flag){//现在灯是开着的
					img.setAttribute("src","off.png")
					h1.innerHTML="灯灭了！"
					h1.setAttribute("style","color:#000000")
					flag=false;
				}
				else{
					img.setAttribute("src","on.png")//灯是关着的
					h1.innerHTML="灯亮了！"
					h1.setAttribute("style","color:#FF0000")
					flag=true;
				}
			}
		</script>
	</head>
	<body>
		<div class="con" style="text-align: center;" onclick="fun()">
			<img src="off.png" width="200px" >
			<h1>点击开灯</h1>
		</div>
	</body>
</html>
